package com.ruoyi.project.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cms.domain.BizResume;
import com.ruoyi.project.cms.service.IBizResumeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 学生简历Controller
 *
 * @author ruoyi
 * @date 2023-03-18
 */
@RestController
@RequestMapping("/cms/resume")
public class BizResumeController extends BaseController
{
    @Autowired
    private IBizResumeService bizResumeService;

    /**
     * 查询学生简历列表
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizResume bizResume)
    {
        startPage();
        //判断当前是否为管理员用户,如果是则显示全部,否则只显示自己录入的
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userId = loginUser.getUserId();
        if(!loginUser.getUser().isAdmin()){
            //不是管理员
            bizResume.setUserId(userId);
        }

        List<BizResume> list = bizResumeService.selectBizResumeList(bizResume);
        return getDataTable(list);
    }

    /**
     * 导出学生简历列表
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:export')")
    @Log(title = "学生简历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizResume bizResume)
    {
        List<BizResume> list = bizResumeService.selectBizResumeList(bizResume);
        ExcelUtil<BizResume> util = new ExcelUtil<BizResume>(BizResume.class);
        util.exportExcel(response, list, "学生简历数据");
    }

    /**
     * 获取学生简历详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizResumeService.selectBizResumeById(id));
    }

    /**
     * 新增学生简历
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:add')")
    @Log(title = "学生简历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizResume bizResume)
    {

        Long userId = SecurityUtils.getLoginUser().getUserId();
        bizResume.setUserId(userId);
        return toAjax(bizResumeService.insertBizResume(bizResume));
    }

    /**
     * 修改学生简历
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:edit')")
    @Log(title = "学生简历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizResume bizResume)
    {
        return toAjax(bizResumeService.updateBizResume(bizResume));
    }

    /**
     * 删除学生简历
     */
    @PreAuthorize("@ss.hasPermi('cms:resume:remove')")
    @Log(title = "学生简历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizResumeService.deleteBizResumeByIds(ids));
    }
}
